package cn.kgc.config;


import cn.kgc.handler.MyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration   //标识配置类
public class MyWebConfig implements WebMvcConfigurer {

   /* @Bean
    public MyInterceptor myInterceptor(){
        return new MyInterceptor();
    }*/

   @Autowired
   private MyInterceptor myInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器
        InterceptorRegistration interceptor = registry.addInterceptor(myInterceptor);

        //拦截哪些资源:拦截所有
        interceptor.addPathPatterns("/**");

        //放行哪些资源
        //interceptor.excludePathPatterns("/**/*.js");
        interceptor.excludePathPatterns("/**/emp");



    }
}
